import { _getList } from '@/views/sys/areaManage/src/store'

export default {
  data() {
    return {
      areaList: [],
      areaDefaultProps: {
        children: "children",
        label: "name",
        checkStrictly: true,
        emitPath: false,
        value: "id"
      },
      areaIds: [],
      area_temp: ''
    }
  },
  methods: {
    async getAllArea() {
      const { data, success, message } = await _getList()
      if (success) {
        this.areaList = data
      } else {
        this.$message({ type: 'error', message })
      }
    },
    getAllAreaIds(data) {
      const temp = data
      temp.value && this.areaIds.push(temp.value)
      if (temp.children && temp.children.length) {
        for (let i = 0, len = temp.children.length; i < len; i++) {
          this.getAllAreaIds(temp.children[i])
        }
      }
    },
    handleChange() {
      this.areaIds = []
      const checkNode = this.$refs.cascader.getCheckedNodes()[0]
      this.getAllAreaIds(checkNode)
    },
    transformDisable(temp) {
      const data = JSON.parse(JSON.stringify(temp))
      for (let i = 0, len = data.length; i < len; i++) {
        if (data[i].level !== 3) {
          data[i].disabled = true
        }
        if (data[i].children && data[i].children.length) {
          data[i].children = this.transformDisable(data[i].children)
        }
      }
      return data
    }
  },
  computed: {
    disableAreaList() {
      return this.transformDisable(this.areaList)
    }
  },
  mounted() {
    this.getAllArea()
  }
}
